<!DOCTYPE html>
<html lang="en">
<head>
    <#include "/commonPage.html" />
    <style>
        .grid-panel .datagrid-btable tr {
            height: 120px;
        }
    </style>
    <script>
        $(function () {
            $('#recoveryDevice').click(function () {
                recoveryDevice();
            })

            $('#deleteDevice').click(function () {
                deleteDevice();
            })
        })
    </script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',border:false" style="height:90px;">
    <div><h1 style="color:#133ad5">订单回收站</h1></div>
    <div>
        <HR width="100%" color=#133ad5 SIZE=1>
    </div>
</div>
<div data-options="region:'center',border:false" style="padding:0">
    <div class="grid-panel" style="width: 100%;height: 100%">
        <table id="mydatagrid" class="easyui-datagrid" rownumbers="true" url="/order/listRecycle" pagination="true"
               striped="true"
               data-options="toolbar:'#tb',idField:'id',fit:true,fitColumns:true,onLoadSuccess:function(){$('#mydatagrid').datagrid('clearChecked');}">
            <thead>
            <tr style="height: 100px;">
                <th field="id" checkbox="true"></th>
                <th data-options="field:'billName',width:80">订单名称</th>
                <th data-options="field:'userName',width:80">经手人</th>
                <th data-options="field:'otime',width:80">下单时间</th>
                <th data-options="field:'ctime',width:80">预计完成时间</th>
                <th data-options="field:'specification',width:80">规格</th>
                <th data-options="field:'paper',width:80">纸张/材质</th>
                <th data-options="field:'technology',width:80">工艺</th>
                <th data-options="field:'quantity',width:50">数量</th>
                <th data-options="field:'unitPrice',width:50">单价(元)</th>
                <th data-options="field:'totalMoney',width:80">金额(元)</th>
                <th data-options="field:'received',width:80">已收款(元)</th>
                <th class="img" data-options="field:'picture',width:200" formatter="showpic">图片</th>
                <th data-options="field:'state',width:40" formatter="showmode">状态</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<div id="tb">
    <div>
        <a id="recoveryDevice" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">恢复订单</a>
        <a id="deleteDevice" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">删除订单</a>
    </div>
    <div id="tbsearch" style="padding:3px">
        <span>名称:</span>
        <input id="name" name="name" style="line-height:26px;border:1px solid #ccc">
        <span>状态:</span>
        <input id="state" name="state" class="easyui-combobox" style="line-height:26px;border:1px solid #ccc"
               data-options="panelHeight:'auto',valueField:'id',textField:'text',url:'/json/levelsearch.json',method:'get'">
        <a href="#" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-search'"
           onclick="doSearch()">搜索</a>
    </div>
</div>

<script>
    function doSearch() {
        $('#mydatagrid').datagrid('load', {
            name: $('#name').val(),
            state: $('#state').val()
        });
    }

    function getdatagridchecked() {
        var arr = $('#mydatagrid').datagrid('getSelections');
        var ids = [];
        for (var i in arr) {
            ids.push(arr[i].bId);
        }
        ids = ids.join(",");
        return ids;
    }

    function recoveryDevice() {
        ids = getdatagridchecked();
        if (ids.length == 0) {
            $.messager.alert('提示', '请先选择要恢复的订单!');
            return;
        }
        $.messager.confirm('确认', '是否将选中的订单恢复？', function (r) {
            if (r) {
                $.post('/order/recovery', {ids: ids}, function (data) {
                    if (data == "成功") {
                        $.messager.alert('提示', '已恢复!', undefined, function () {
                            $("#mydatagrid").datagrid("reload");
                            $("#mydatagrid").datagrid("uncheckAll");
                        });
                    } else {
                        $.messager.alert('错误', data, 'error');
                    }
                })
            }
        });
    }

    function deleteDevice() {
        ids = getdatagridchecked();
        if (ids.length == 0) {
            $.messager.alert('提示', '请先选择要彻底删除的订单!');
            return;
        }
        $.messager.confirm('确认', '是否将选中的订单彻底删除？', function (r) {
            if (r) {
                $.post('/order/delete', {ids: ids}, function (data) {
                    if (data == "成功") {
                        $.messager.alert('提示', '已彻底删除订单!', undefined, function () {
                            $("#mydatagrid").datagrid("reload");
                            $("#mydatagrid").datagrid("uncheckAll");
                        });
                    } else {
                        $.messager.alert('错误', data, 'error');
                    }
                })
            }
        });
    }


    function showpic(value, row) {
        if (value != undefined) {
            return "<img class='img' style='width: 200px' height='120px' src='/" + value + "'/>";
        }
        return value;
    }

    function showmode(value, row, index) {
        if (row.state == 1) {
            return "已完结";
        } else {
            return "未完结";
        }
    }
</script>
</body>

</html>